<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :show="show" @click-show="show = !show" :fixed="true" :back="true" color="#fff" title="联名建议"></uni-navbar></view>

		<view class="filter-box" v-if="show">
			<view class="form-box">
				<u-form ref="uForm">
					<u-form-item class="form-item" label="标题"><u-input v-model="motion.title" type="text" placeholder="请输入标题" /></u-form-item>
					<u-form-item class="form-item" label="届次">
						<u-input v-model="jieci" type="select" :select-open="jcShow" placeholder="请选择届次" @click="jcShow = true" />
						<u-select v-model="jcShow" mode="mutil-column-auto" :list="jcList" @confirm="jcConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="类型">
						<u-input v-model="kind" type="select" :select-open="kindShow" placeholder="请选择类型" @click="kindShow = true" />
						<u-select v-model="kindShow" :list="kindList" @confirm="kindConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="分类">
						<u-input v-model="type" type="select" :select-open="typeShow" placeholder="请选择分类" @click="typeShow = true" />
						<u-select v-model="typeShow" :list="typeList" @confirm="typeConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="是否涉密">
						<u-input v-model="isSecret" type="select" :select-open="isSecretShow" placeholder="请选择" @click="isSecretShow = true" />
						<u-select v-model="isSecretShow" :list="isSecretList" @confirm="isSecretConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="是否公开">
						<u-input v-model="isOpen" type="select" :select-open="isOpenShow" placeholder="请选择" @click="isOpenShow = true" />
						<u-select v-model="isOpenShow" :list="isOpenList" @confirm="isOpenConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="是否重点">
						<u-input v-model="isKey" type="select" :select-open="isKeyShow" placeholder="请选择" @click="isKeyShow = true" />
						<u-select v-model="isKeyShow" :list="isKeyList" @confirm="isKeyConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="是否优秀">
						<u-input v-model="isGood" type="select" :select-open="isGoodShow" placeholder="请选择" @click="isGoodShow = true" />
						<u-select v-model="isGoodShow" :list="isGoodList" @confirm="isGoodConfirm"></u-select>
					</u-form-item>
				</u-form>
			</view>
			<view class="fiexd-btm">
				<view class="flex-box">
					<u-button class="form-btn" type="default" @click="resert">清除</u-button>
					<u-button class="form-btn" type="error" @click="filter">确定</u-button>
				</view>
			</view>
		</view>

		<view class="search-view">
			<u-search class="search-input" shape="square" bg-color="#fff" v-model="motion.title" :show-filter="true" @search="search" @custom="show = !show"></u-search>
		</view>
		<u-tabs class="btm-tabs" :list="tabsList" :is-scroll="true" :current="tabsCurrent" @change="tabsChange"></u-tabs>

		<view class="list-box" :style="{ background: loading == 'nodata' ? 'none' : '#fff' }">
			<view class="list-info_01" v-for="(item, index) of proposalList" :key="item.id" @click="navTo(item)">
				<view class="info-title">{{ item.title }}</view>
				<view class="info-btm">
					<view class="btm-left clamp">
						<text class="left-name">{{ item.createByName }}</text>
						<text class="left-name">{{ item.kindName }}</text>
						<text class="left-time">{{ item.createTime }}</text>
					</view>
					<view class="btm-right">
						<view class="right-type" :style="'color:' + colorMap[item.nodeStatus]">{{ item.nodeStatusName }}</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="loading" />
		</view>

		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			scrollTop: 0,
			show: false,
			tabsCurrent: 0,
			tabsList: [
				{
					name: '所有',
					value: -1
				},
				{
					name: '待确认',
					value: 0
				},
				{
					name: '已同意',
					value: 1
				},
				{
					name: '已拒绝',
					value: 3
				},
				{
					name: '超期未确认',
					value: 2
				}
			],
			colorMap: {
				0: '#303133',
				1: '#f29100',
				2: '#18b566',
				3: '#dd6161',
				4: '#0099ff',
				5: '#ff9900',
				6: '#19be6b',
				7: '#ff3333',
				8: '#909399',
				21: '#b5bfff',
				22: '#fcbd71',
				23: '#71d5a1',
				24: '#fab6b6',
				25: '#909399'
			},
			nodeStatus: -1,
			title: '',
			jieci: '',
			jcShow: false,
			jclist: [],
			kind: '',
			kindShow: false,
			kindList: [
				{
					value: '1',
					label: '个人建议'
				},
				{
					value: '2',
					label: '集体建议'
				},
				{
					value: '3',
					label: '联名建议'
				}
			],

			type: '',
			typeShow: false,
			typeList: [],

			isSecret: '',
			isSecretShow: false,
			isSecretList: [
				{
					value: '1',
					label: '涉密'
				},
				{
					value: '0',
					label: '不涉密'
				}
			],

			isOpen: '',
			isOpenShow: false,
			isOpenList: [
				{
					value: '3',
					label: '公开'
				},
				{
					value: '0',
					label: '不公开'
				}
			],

			isKey: '',
			isKeyShow: false,
			isKeyList: [
				{
					value: '1',
					label: '重点'
				},
				{
					value: '0',
					label: '非重点'
				}
			],

			isGood: '',
			isGoodShow: false,
			isGoodList: [
				{
					value: '1',
					label: '优秀'
				},
				{
					value: '2',
					label: '良好'
				},
				{
					value: '3',
					label: '较差'
				}
			],

			startTime: '',
			endTime: '',
			signFlag: '',
			proposalList: [],

			motion: {
				ciId: '',
				jieId: '',
				type: '',
				kind: '',
				dateRangeSea: '',
				nodeStatus: '-1',
				title: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad(option) {
		this.loadLogin();
		if (option && option.status) {
			this.nodeStatus = option.status;
			this.signFlag = option.status;
			if (option.status == '0') {
				this.tabsCurrent = 1;
			}
			if (option.status == 1) {
				this.tabsCurrent = 2;
			}
			if (option.status == 2) {
				this.tabsCurrent = 4;
			}
			if (option.status == 3) {
				this.tabsCurrent = 3;
			}
		}
		this.loadData();
		this.jieciData();
		this.loadDict('motion_type', 'typeList');
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.sysUser) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			if (this.nodeStatus == -1) {
				this.motion.nodeStatus = '';
			}
			if (this.signFlag == -1) {
				this.signFlag = '';
			}
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				currentUserId: this.userId,
				motion: this.motion,
				signFlag: this.signFlag
			};
			this.$request('/motion/jointList', data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.proposalList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.proposalList = this.proposalList.concat(res.data.records);
				this.loaded = true;
				if (this.proposalList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		timeChange({ date, dt }, idx) {
			this[idx] = date.year + '-' + date.month2 + '-' + date.day2;
		},
		tabsChange(index) {
			this.tabsCurrent = index;
			this.typeFun(this.tabsList[index].value);
		},
		jcConfirm(e) {
			this.jieci = e[0].label + e[1].label;
			this.motion.jieId = e[0].value;
			this.motion.ciId = e[1].value;
		},
		typeConfirm(e) {
			this.type = e[0].label;
			this.motion.type = e[0].value;
		},
		kindConfirm(e) {
			this.kind = e[0].label;
			this.motion.kind = e[0].value;
		},
		isSecretConfirm(e) {
			this.isSecret = e[0].label;
			this.motion.isSecret = e[0].value;
		},
		isOpenConfirm(e) {
			this.isOpen = e[0].label;
			this.motion.isOpen = e[0].value;
		},
		isKeyConfirm(e) {
			this.isKey = e[0].label;
			this.motion.isKey = e[0].value;
		},
		isGoodConfirm(e) {
			this.isGood = e[0].label;
			this.motion.isGood = e[0].value;
		},
		filter() {
			this.show = false;
			this.motion.dateRangeSea = this.dateRangeSea;
			this.loadData('refresh');
		},
		resert() {
			this.show = false;
			this.motion.title = '';
			this.jieci = '';
			this.motion.jieId = '';
			this.motion.ciId = '';
			this.type = '';
			this.motion.type = '';
			this.kind = '';
			this.motion.kind = '';
			this.isSecret = '';
			this.motion.isSecret = '';
			this.isOpen = '';
			this.motion.isOpen = '';
			this.isKey = '';
			this.motion.isKey = '';
			this.isGood = '';
			this.motion.isGood = '';
			this.dateRangeSea = '';
			this.motion.dateRangeSea = '';
			this.loadData('refresh');
		},
		search(e) {
			this.motion.title = e;
			this.loadData('refresh');
		},
		typeFun(e) {
			this.nodeStatus = e;
			this.signFlag = e.toString();
			this.loadData('refresh');
		},
		loadDict(type, list) {
			this.$request('/system/sys-dict/dictList', {
				clientCode: this.clientCode,
				sysDict: {
					dictType: type
				}
			}).then((res) => {
				this[list] = [];
				res.data.forEach((item) => {
					this[list].push({
						label: item.dictName,
						value: item.dictValue
					});
				});
			});
		},
		jieciData() {
			let data = {
				clientCode: this.clientCode,
				jieCi: {
					pid: ''
				}
			};
			this.$request('/jie-ci/list', data).then((res) => {
				this.jcList = [];
				let jieArr = [];
				let ciArr = [];
				res.data.forEach((item) => {
					data.jieCi.pid = item.id;
					this.$request('/jie-ci/list', data).then((res) => {
						ciArr = [];
						res.data.forEach((key) => {
							ciArr.push({
								value: key.id,
								label: key.name
							});
						});
						this.jcList.push({
							value: item.id,
							label: item.name,
							children: ciArr
						});
					});
				});
			});
		},
		navTo(item) {
			uni.navigateTo({
				url: '/pagesB/proposal/detail_lianming?id=' + item.id + '&signFlag=' + item.signFlag
			});
		}
	}
};
</script>

<style lang="scss">
.list-box {
	padding: 0 30rpx;
	background-color: #fff;
}

.filter-box {
	position: fixed;
	left: 0;
	top: 0;
	bottom: 0;
	right: 0;
	z-index: 998;
	background-color: #fff;
}

.form-box {
	.form-item {
		@include mp-flex;
		border-bottom: 20rpx solid #f5f7fa;
	}
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}
</style>
